package com.breakfast.fun.ui.mall;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.breakfast.fun.R;
import com.breakfast.fun.adapter.other.CommFragmentPagerAdapter;
import com.breakfast.fun.base.BaseFragment;
import com.breakfast.fun.ui.mall.cart.GoodCartActivity;
import com.breakfast.fun.view.widget.TitleBarView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * Created by Administrator on 2016/8/22.
 */
public class MallFragment extends BaseFragment<MallPresenter, MallModel> implements MallContract.View {

    //    @Bind(R.id.tl_mall)
//    TabLayout mTlMall;
    @Bind(R.id.vp_mall)
    ViewPager mVpMall;
    @Bind(R.id.tbv_mall)
    TitleBarView mTbvMall;


    @Override
    public int getLayoutId() {
        return R.layout.fragment_mall;
    }

    @Override
    public void initView() {

        // mTbvMall.setNoBack("早范商城","购物车");
        mTbvMall.setAll("早范商城");
        mTbvMall.ivTitleBack.setVisibility(View.GONE);
        mTbvMall.setRightImg(R.drawable.ic_mall_cart);
        mTbvMall.setRightListener(v -> {
            Intent intent = new Intent(context, GoodCartActivity.class);
            intent.putExtra("isFromMall", true);
            startActivity(intent);
        });

//        mTlMall.addTab(mTlMall.newTab().setText("特色早餐用具"));
//        mTlMall.addTab(mTlMall.newTab().setText("海外营养早餐"));

        List<Fragment> list = new ArrayList<>();
        list.add(new ToolFragment());
//        list.add(new AbroadFragment());

        CommFragmentPagerAdapter adapter = new CommFragmentPagerAdapter(getChildFragmentManager(), list);
        mVpMall.setAdapter(adapter);

        /*mTlMall.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                //点击TabLayout联动ViewPager
                mVpMall.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });*/

        /*mVpMall.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                //切换viewpager时联动tab
                if (mTlMall.getTabCount() > 0) {
                    mTlMall.getTabAt(position).select();
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });*/

    }

}
